{extend name="common@list" /}
{block name="topnav"}
	<nav class="breadcrumb">
		<i class="Hui-iconfont">&#xe67f;</i> 首页
		<span class="c-gray en">&gt;</span> 教务管理
		<span class="c-gray en">&gt;</span> 班级列表
		<a class="btn btn-success radius r"
			style="line-height:1.6em;margin-top:3px"
			href="javascript:location.replace(location.href);"
			title="刷新" >
			<i class="Hui-iconfont">&#xe68f;</i>
	</a>
	</nav>
{/block}
{block name="bouttons"}
	<div class="cl pd-5 bg-1 bk-gray mt-20">
		<span class="l">
			<!-- 删除按钮 -->
			<a href="javascript:;" onclick="dels('/banji/m')" class="btn btn-danger radius">
				<i class="Hui-iconfont">&#xe6e2;</i>
			批量删除
			</a>
			<!-- 添加按钮 -->
			<a href="javascript:;" onclick=add('添加班级',"/banji/create",600,280) class="btn btn-primary radius">
				<i class="Hui-iconfont">&#xe600;</i>
				添加班级
			</a>
		</span>
		<span class="r">
			共有数据：<strong>{$list.count}</strong> 条
		</span>
	</div>
{/block}
{block name="tables"}
	<table id="table1" class="display" cellspacing="0" width="100%">
		<thead>
			<tr>
				<th><input type="checkbox" name="" value=""></th>
				<th>ID</th>
				<th>班级名称</th>
				<th>学校</th>
				<th>入学年</th>
				<th>排序</th>
				<th>学生人数</th>
				<th>状态</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>


{/block}
{block name="myjs"}
<script type="text/javascript">

	// 定义DTajax参数
	var myajax = {
		url: "{:url('ajaxdata')}",
		type: "get",
		data: {},
	};

	// 定义列参数
	var mycolumns = [
        { "data": "id" },
        { "data": "id" },
        { "data": "title","name":"id"},
        { "data": "school" },
        { "data": "ruxuenian"},
        { "data": "paixu" },
        { "data": "stusum" },
        { "data": "status" },
        { "data": "id" },
	];

	// 定义修改列参数
	var mycolumnDefs =[
		// 对象格式
		{
			"targets": 0,			
			"render": function(data, type, row, meta) {
				return '<input type="checkbox" name="test" value="' + row.id + '" />'
			}
		},
		{
			"targets": -1,
			"className":'.td-manage',			
			"render": function(data, type, row, meta) {
					// 停用按钮
					stopbut = '<a style="text-decoration:none" onClick="stop(this,'+ row.id +')" href="javascript:;" title="停用"><i class="Hui-iconfont">&#xe631;</i></a>';
					// 启用按钮
					startbut = '<a style="text-decoration:none" onClick="start(this,'+ row.id +')" href="javascript:;" title="启用"><i class="Hui-iconfont">&#xe6e1;</i></a>';
					// 编辑按钮
					editbut = '<a title="编辑" href="javascript:void(0);" onclick=add("编辑","/banji/'+row.id+'/edit",600,280) class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe60c;</i></a>';
					delbut = '<a title="删除" href="javascript:void(0);" onclick=del(this,"/banji/'+row.id+'") class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>';
					bfbut = '<a title="前移" href="javascript:void(0);" onclick=yidong(this,"/banji/'+row.id+'/yidong",-1) class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6d4;</i></a>';
					endbut = '<a title="后移" href="javascript:void(0);" onclick=yidong(this,"/banji/'+row.id+'/yidong",1) class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6d7;</i></a>';
					if(row.status == '已停用')
					{
						buts = startbut + bfbut + endbut;
					}else{
						buts = stopbut + bfbut + endbut;
					} 

					return buts;
                }
        },
        {
			"targets": -2,
			"className":'.td-status',
			"render": function(data, type, row, meta) {
                    if(row.status == '已停用')
                    {
                    	d = "<span class='label label-error radius'>" + row.status + "</span>";
                    }else{
                    	d = "<span class='label label-success radius'>" + row.status + "</span>";
                    }

                    return d;
                  },
        },
        {
        	"orderable": false,
        	"targets": [0,1,-3,-1]
        }, 
	];

	/*用户-删除*/
	function yidong(obj,url,caozuo){
		layer.confirm('确认要移动班级位置吗？',function(index){
			$.ajax({
				type: 'POST',
				url: url,
				data: {
					cz:caozuo,
				},
				dataType: 'json',
				success: function(data){
					
					if(data.val == false){
						layer.alert(data.msg);
						return true;
					}
					var yd = $(obj).parents("tr").html();
					if( caozuo === 1)
					{
						$(obj).parents("tr").prev().bofore('<tr role="row">' + yd + '</tr>');
						
					} else {
						$(obj).parents("tr").next().after('<tr role="row">' + yd + '</tr>');
					}
					$(obj).parents("tr").remove();
					layer.alert(data.msg);
					return true;
				},
				error:function(data) {
					layer.alert('移动失败');
				},
			});		
		});
	}
</script>
{/block}